//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.baidu.trace.api.fence.AlarmPoint;
import com.baidu.trace.api.fence.CircleFence;
import com.baidu.trace.api.fence.DistrictFence;
import com.baidu.trace.api.fence.FenceAlarmInfo;
import com.baidu.trace.api.fence.FenceInfo;
import com.baidu.trace.api.fence.FenceShape;
import com.baidu.trace.api.fence.HistoryAlarmRequest;
import com.baidu.trace.api.fence.MonitoredAction;
import com.baidu.trace.api.fence.MonitoredStatus;
import com.baidu.trace.api.fence.MonitoredStatusInfo;
import com.baidu.trace.api.fence.PolygonFence;
import com.baidu.trace.api.fence.PolylineFence;
import com.baidu.trace.api.track.CacheTrackInfo;
import com.baidu.trace.ar.a;
import com.baidu.trace.c.e;
import com.baidu.trace.model.CoordType;
import com.baidu.trace.model.LatLng;
import java.io.File;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import org.json.JSONException;
import org.json.JSONObject;

public class am extends Thread {
    private static u a = null;
    private static SQLiteDatabase b = null;
    private static boolean c = false;
    private static File d = null;
    private static int e = 0;
    private int f = 0;
    private String g = "";

    public void run() {
        switch(this.f) {
            case 0:
                String var1 = this.g;
                if(b != null) {
                    b.beginTransaction();

                    try {
                        ContentValues var2;
                        (var2 = new ContentValues()).put("entity_name", var1);
                        StringBuffer var3;
                        (var3 = new StringBuffer("entity_name")).append(" like ? ");
                        String[] var4 = new String[]{""};
                        b.update("trace_location", var2, var3.toString(), var4);
                        (var2 = new ContentValues()).put("monitored_person", var1);
                        (var3 = new StringBuffer("monitored_person")).append(" like ? ");
                        b.update("trace_fence", var2, var3.toString(), var4);
                        b.setTransactionSuccessful();
                    } catch (Exception var15) {
                        ;
                    } finally {
                        b.endTransaction();
                    }
                }

                a(this.g);
                if(b != null) {
                    b.beginTransaction();

                    try {
                        StringBuffer var17;
                        (var17 = new StringBuffer("create_time")).append(" < ? ");
                        String[] var18 = new String[]{String.valueOf(e.b() - 604800L)};
                        b.delete("trace_fence_alarm", var17.toString(), var18);
                        b.setTransactionSuccessful();
                    } catch (Exception var13) {
                        ;
                    } finally {
                        b.endTransaction();
                    }
                }
                break;
            case 1:
                a((Context)null, (String)null, (String[])null);
        }

    }

    private static void a(String var0) {
        if(b != null) {
            StringBuilder var1;
            (var1 = new StringBuilder("select distinct ")).append("entity_name from ").append("trace_location");
            u var10000 = a;
            Cursor var3 = u.b(b, var1.toString(), (String[])null);
            if(var3 != null) {
                bd.h = var3.getCount() > 0;

                while(var3.moveToNext()) {
                    String var2 = var3.getString(0);
                    if(var0.equals(var2)) {
                        bd.g = true;
                        break;
                    }
                }

                var3.close();
            }
        }
    }

    protected static void a(boolean var0) {
        LinkedList var1 = new LinkedList();
        if(!bd.g && aw.a != null && !aw.a.isEmpty()) {
            var1.addAll(aw.a);
            aw.a.removeAll(var1);
        }

        if(bd.c != null) {
            var1.addAll(bd.c);
            bd.c.removeAll(var1);
        }

        if(var1 != null && !var1.isEmpty()) {
            a((Queue)var1);
        }

        var1.clear();
        if(var0) {
            a();
        }

    }

    private static void a(Queue<a> var0) {
        if(b != null) {
            d();
            b.beginTransaction();

            try {
                Iterator var7 = var0.iterator();

                while(var7.hasNext()) {
                    a var1 = (a)var7.next();
                    StringBuffer var2;
                    (var2 = new StringBuffer("insert into ")).append("trace_location(").append("loc_time, ").append("entity_name, ").append("location_data) values(?,?,?);");
                    Object[] var8 = new Object[]{Long.valueOf(var1.c), var1.a, var1.b};
                    b.execSQL(var2.toString(), var8);
                    var7.remove();
                }

                b.setTransactionSuccessful();
                return;
            } catch (Exception var5) {
                ;
            } finally {
                b.endTransaction();
            }

        }
    }

    protected static String a(String var0, int var1, Deque<a> var2) {
        if(b == null) {
            return null;
        } else {
            StringBuffer var10;
            (var10 = new StringBuffer("select * from ")).append("trace_location");
            String[] var3 = null;
            if(!com.baidu.trace.b.a.d()) {
                return null;
            } else {
                if(bd.g) {
                    var10.append(" where entity_name").append(" like ?  limit 0,?;");
                    var3 = new String[]{var0, String.valueOf(10)};
                } else if(bd.h) {
                    var10.append(" where entity_name").append(" like (select entity_name").append(" from trace_location").append(" limit 1) limit 0,?;");
                    var3 = new String[]{String.valueOf(10)};
                }

                u var10000 = a;
                Cursor var9 = u.b(b, var10.toString(), var3);
                if(var9 == null) {
                    return null;
                } else if(0 == (aw.c = var9.getCount())) {
                    if(bd.g) {
                        bd.g = false;
                    } else if(bd.h) {
                        bd.h = false;
                    }

                    var9.close();
                    return null;
                } else {
                    String var11 = null;

                    while(var9.moveToNext()) {
                        long var7 = var9.getLong(var9.getColumnIndex("loc_time"));
                        var11 = var9.getString(var9.getColumnIndex("entity_name"));
                        byte[] var12 = var9.getBlob(var9.getColumnIndex("location_data"));
                        if(var2 != null) {
                            a var13 = new a(var11, var12, var7);
                            var2.offer(var13);
                        }
                    }

                    var9.close();
                    return var11;
                }
            }
        }
    }

    protected static void a(String var0, int var1) {
        if(b != null) {
            b.beginTransaction();

            try {
                StringBuffer var2;
                (var2 = new StringBuffer("delete from ")).append("trace_location where rowid in(select rowid from ").append("trace_location where ").append("entity_name like ? limit 0,?);");
                String[] var7 = new String[]{var0, String.valueOf(var1)};
                u var10000 = a;
                u.a(b, var2.toString(), var7);
                b.setTransactionSuccessful();
                return;
            } catch (Exception var5) {
                ;
            } finally {
                b.endTransaction();
            }

        }
    }

    protected static long a(Context var0, String var1, String var2, CoordType var3, int var4, FenceShape var5, String var6) {
        a(var0);
        long var7 = -1L;
        if(b == null) {
            return -1L;
        } else {
            d();
            b.beginTransaction();

            try {
                ContentValues var13;
                (var13 = new ContentValues()).put("fence_name", var1);
                var13.put("monitored_person", var2);
                var13.put("coord_type", var3.name());
                var13.put("denoise", Integer.valueOf(var4));
                var13.put("fence_shape", var5.name());
                var13.put("create_time", e.c());
                var13.put("modify_time", e.c());
                var13.put("monitored_status", MonitoredStatus.unknown.name());
                var13.put("fence_extern_info", var6);
                var7 = b.insert("trace_fence", (String)null, var13);
                b.setTransactionSuccessful();
            } catch (Exception var11) {
                ;
            } finally {
                b.endTransaction();
            }

            return var7;
        }
    }

    protected static boolean a(Context var0, long var1, String var3, String var4, CoordType var5, int var6, FenceShape var7, String var8) {
        a(var0);
        if(b == null) {
            return false;
        } else {
            int var14 = 0;
            b.beginTransaction();

            try {
                ContentValues var9;
                (var9 = new ContentValues()).put("fence_name", var3);
                var9.put("monitored_person", var4);
                var9.put("coord_type", var5.name());
                var9.put("denoise", Integer.valueOf(var6));
                var9.put("fence_shape", var7.name());
                var9.put("fence_extern_info", var8);
                var9.put("modify_time", e.c());
                StringBuffer var16;
                (var16 = new StringBuffer("fence_id")).append(" = ? ");
                String[] var15 = new String[]{String.valueOf(var1)};
                var14 = b.update("trace_fence", var9, var16.toString(), var15);
                b.setTransactionSuccessful();
            } catch (Exception var12) {
                ;
            } finally {
                b.endTransaction();
            }

            return var14 > 0;
        }
    }

    protected static CircleFence a(Context var0, long var1) {
        a(var0);
        if(b == null) {
            return null;
        } else {
            CircleFence var3 = null;
            String[] var11 = new String[]{"fence_id", "fence_name", "monitored_person", "coord_type", "denoise", "fence_shape", "fence_extern_info"};
            String[] var13 = new String[]{String.valueOf(var1)};
            StringBuffer var2;
            (var2 = new StringBuffer("fence_id")).append(" = ? ");
            Cursor var12 = b.query("trace_fence", var11, var2.toString(), var13, (String)null, (String)null, (String)null);
            if(var12 == null) {
                return null;
            } else {
                if(var12.moveToNext()) {
                    long var8 = var12.getLong(0);
                    String var14 = var12.getString(1);
                    String var15 = var12.getString(2);
                    CoordType var16 = CoordType.valueOf(var12.getString(3));
                    int var4 = var12.getInt(4);
                    String var5 = var12.getString(5);
                    String var6 = var12.getString(6);
                    if(!FenceShape.circle.name().equals(var5)) {
                        if(var12 != null) {
                            var12.close();
                        }

                        return null;
                    }

                    var3 = CircleFence.buildLocalFence(var8, var14, var15, (LatLng)null, 0.0D, var4, var16);

                    try {
                        com.baidu.trace.a.a(new JSONObject(var6), var3);
                    } catch (JSONException var10) {
                        ;
                    }
                }

                if(var12 != null) {
                    var12.close();
                }

                return var3;
            }
        }
    }

    protected static void a(Context var0, String var1, List<Long> var2, List<FenceInfo> var3) {
        a(var0);
        if(b != null) {
            String[] var16 = new String[]{"fence_id", "fence_name", "monitored_person", "coord_type", "denoise", "fence_shape", "create_time", "modify_time", "fence_extern_info"};
            StringBuffer var4 = new StringBuffer();
            String[] var5 = null;
            if(var2 != null && !var2.isEmpty()) {
                StringBuffer var8 = new StringBuffer();
                if(e.a(var1)) {
                    var5 = new String[var2.size() + 1];
                } else {
                    var5 = new String[var2.size()];
                }

                for(int var9 = 0; var9 < var2.size(); ++var9) {
                    var8.append('?').append(',');
                    var5[var9] = String.valueOf(var2.get(var9));
                }

                var8.deleteCharAt(var8.length() - 1);
                var4.append("fence_id in( ").append(var8.toString()).append(")");
                if(e.a(var1)) {
                    var4.append(" and ");
                    var4.append("monitored_person like ? ");
                    var5[var5.length - 1] = var1;
                }
            } else if(e.a(var1)) {
                var5 = new String[]{var1};
                var4.append("monitored_person like ? ");
            }

            Cursor var17 = b.query("trace_fence", var16, var4.toString(), var5, (String)null, (String)null, (String)null);
            if(var17 != null) {
                try {
                    while(var17.moveToNext()) {
                        long var23 = var17.getLong(0);
                        var1 = var17.getString(1);
                        String var20 = var17.getString(2);
                        CoordType var21 = CoordType.valueOf(var17.getString(3));
                        int var22 = var17.getInt(4);
                        String var6 = var17.getString(5);
                        String var7 = var17.getString(6);
                        String var10 = var17.getString(7);
                        String var11 = var17.getString(8);
                        JSONObject var24 = new JSONObject(var11);
                        if(FenceShape.circle.name().equals(var6)) {
                            CircleFence var18 = CircleFence.buildLocalFence(var23, var1, var20, (LatLng)null, 0.0D, var22, var21);
                            com.baidu.trace.a.a(var24, var18);
                            FenceInfo var19 = new FenceInfo(FenceShape.circle, var18, (PolygonFence)null, (PolylineFence)null, (DistrictFence)null, var7, var10);
                            var3.add(var19);
                        }
                    }

                    return;
                } catch (Exception var14) {
                    ;
                } finally {
                    if(var17 != null) {
                        var17.close();
                    }

                }

            }
        }
    }

    protected static boolean a(Context var0, long var1, String var3) {
        a(var0);
        if(b == null) {
            return false;
        } else {
            int var8 = 0;
            b.beginTransaction();

            try {
                String[] var9 = new String[]{String.valueOf(var1), var3};
                StringBuffer var2;
                (var2 = new StringBuffer()).append("fence_id = ? ");
                var2.append(" and ");
                var2.append("monitored_person like ? ");
                var8 = b.delete("trace_fence", var2.toString(), var9);
                b.setTransactionSuccessful();
            } catch (Exception var6) {
                ;
            } finally {
                b.endTransaction();
            }

            return var8 > 0;
        }
    }

    protected static boolean a(Context var0, String var1) {
        a(var0);
        if(b == null) {
            return false;
        } else {
            b.beginTransaction();

            try {
                String var7 = null;
                String[] var2 = null;
                if(e.a(var1)) {
                    StringBuffer var8;
                    (var8 = new StringBuffer("monitored_person")).append(" like ? ");
                    var2 = new String[]{var1};
                    var7 = var8.toString();
                }

                b.delete("trace_fence", var7, var2);
                b.setTransactionSuccessful();
                return true;
            } catch (Exception var5) {
                ;
            } finally {
                b.endTransaction();
            }

            return false;
        }
    }

    protected static void a(Context var0, String var1, String[] var2) {
        a(var0);
        if(b != null) {
            String[] var16 = new String[]{"fence_id", "fence_name", "monitored_person", "coord_type", "denoise", "fence_shape", "monitored_status", "fence_extern_info"};

            Cursor var17;
            try {
                var17 = b.query("trace_fence", var16, (String)null, (String[])null, (String)null, (String)null, (String)null);
            } catch (Exception var13) {
                return;
            }

            if(var17 != null) {
                try {
                    while(var17.moveToNext()) {
                        long var5 = var17.getLong(0);
                        var1 = var17.getString(1);
                        String var19 = var17.getString(2);
                        CoordType var3 = CoordType.valueOf(var17.getString(3));
                        int var4 = var17.getInt(4);
                        String var7 = var17.getString(5);
                        MonitoredStatus var8 = MonitoredStatus.valueOf(var17.getString(6));
                        String var9 = var17.getString(7);
                        if(FenceShape.circle.name().equals(var7)) {
                            JSONObject var20 = new JSONObject(var9);
                            CircleFence var18 = CircleFence.buildLocalFence(var5, var1, var19, (LatLng)null, 0.0D, var4, var3);
                            com.baidu.trace.a.a(var20, var18);
                            ar.a.a(Long.valueOf(var5).longValue(), var18);
                            ar.a.a(Long.valueOf(var5).longValue(), var8);
                        }
                    }

                    return;
                } catch (Exception var14) {
                    ;
                } finally {
                    if(var17 != null) {
                        var17.close();
                    }

                }

            }
        }
    }

    protected static void a(CircleFence var0, MonitoredAction var1, String var2, String var3) {
        if(b != null) {
            d();
            b.beginTransaction();

            try {
                ContentValues var4;
                (var4 = new ContentValues()).put("fence_id", Long.valueOf(var0.getFenceId()));
                var4.put("fence_name", var0.getFenceName());
                var4.put("monitored_person", var0.getMonitoredPerson());
                var4.put("monitored_action", var1.name());
                var4.put("create_time", Long.valueOf(e.b()));
                var4.put("cur_point", var2);
                var4.put("pre_point", var3);
                b.insert("trace_fence_alarm", (String)null, var4);
                b.setTransactionSuccessful();
                return;
            } catch (Exception var7) {
                ;
            } finally {
                b.endTransaction();
            }

        }
    }

    protected static void a(Context var0, HistoryAlarmRequest var1, List<FenceAlarmInfo> var2) {
        a(var0);
        if(b != null) {
            String[] var13 = new String[]{"fence_id", "fence_name", "monitored_person", "monitored_action", "cur_point", "pre_point"};
            ArrayList var3 = new ArrayList();
            String var4 = var1.getMonitoredPerson();
            StringBuffer var5 = new StringBuffer();
            if(e.a(var4)) {
                var5.append("monitored_person like ? ");
                var3.add(var4);
            }

            List var17 = var1.getFenceIds();
            if(var1.getStartTime() > 0L) {
                var5.append(" and create_time").append(" >= ? ");
                var3.add(String.valueOf(var1.getStartTime()));
            }

            if(var1.getEndTime() > 0L) {
                var5.append(" and create_time").append(" <= ? ");
                var3.add(String.valueOf(var1.getEndTime()));
            }

            if(var17 != null && !var17.isEmpty()) {
                StringBuffer var6 = new StringBuffer();

                for(int var10 = 0; var10 < var17.size(); ++var10) {
                    var6.append('?').append(',');
                    var3.add(String.valueOf(var17.get(var10)));
                }

                var6.deleteCharAt(var6.length() - 1);
                var5.append(" and fence_id").append(" in( ").append(var6.toString()).append(")");
            }

            String[] var19 = new String[var3.size()];
            var3.toArray(var19);
            Cursor var14 = b.query("trace_fence_alarm", var13, var5.toString(), var19, (String)null, (String)null, (String)null);
            if(var14 != null) {
                while(true) {
                    String var15;
                    long var21;
                    do {
                        if(!var14.moveToNext()) {
                            if(var14 != null) {
                                var14.close();
                            }

                            return;
                        }

                        var21 = var14.getLong(0);
                        var15 = var14.getString(1);
                        var4 = var14.getString(2);
                    } while(!var1.getMonitoredPerson().equals(var4));

                    MonitoredAction var18 = MonitoredAction.valueOf(var14.getString(3));
                    String var20 = var14.getString(4);
                    String var7 = var14.getString(5);
                    AlarmPoint var8 = new AlarmPoint();
                    AlarmPoint var9 = new AlarmPoint();

                    try {
                        com.baidu.trace.a.a(new JSONObject(var20), CoordType.bd09ll, var8, String.class);
                        com.baidu.trace.a.a(new JSONObject(var7), CoordType.bd09ll, var9, String.class);
                    } catch (JSONException var12) {
                        continue;
                    }

                    FenceAlarmInfo var16 = new FenceAlarmInfo(var21, var15, var4, var18, var8, var9);
                    var2.add(var16);
                }
            }
        }
    }

    protected static void a(long var0, MonitoredStatus var2) {
        if(b != null) {
            b.beginTransaction();

            try {
                ContentValues var3;
                (var3 = new ContentValues()).put("monitored_status", var2.name());
                StringBuffer var9;
                (var9 = new StringBuffer("fence_id")).append(" = ? ");
                String[] var8 = new String[]{String.valueOf(var0)};
                b.update("trace_fence", var3, var9.toString(), var8);
                b.setTransactionSuccessful();
                return;
            } catch (Exception var6) {
                ;
            } finally {
                b.endTransaction();
            }

        }
    }

    protected static void a(Context var0, List<Long> var1, String var2, List<MonitoredStatusInfo> var3) {
        a(var0);
        if(b != null) {
            String[] var7 = new String[]{"fence_id", "monitored_status"};
            ArrayList var4 = new ArrayList();
            StringBuffer var5;
            (var5 = new StringBuffer("monitored_person")).append(" like ? ");
            var4.add(var2);
            if(var1 != null && !var1.isEmpty()) {
                StringBuffer var9 = new StringBuffer();

                for(int var6 = 0; var6 < var1.size(); ++var6) {
                    var9.append('?').append(',');
                    var4.add(String.valueOf(var1.get(var6)));
                }

                var9.deleteCharAt(var9.length() - 1);
                var5.append(" and fence_id").append(" in( ").append(var9.toString()).append(")");
            }

            String[] var10 = new String[var4.size()];
            var4.toArray(var10);
            Cursor var8 = b.query("trace_fence", var7, var5.toString(), var10, (String)null, (String)null, (String)null);
            if(var8 != null) {
                MonitoredStatusInfo var11;
                for(; var8.moveToNext(); var3.add(var11)) {
                    (var11 = new MonitoredStatusInfo()).setFenceId(var8.getLong(0));
                    if(e.a(var8.getString(1))) {
                        var11.setMonitoredStatus(MonitoredStatus.valueOf(var8.getString(1)));
                    }
                }

                if(var8 != null) {
                    var8.close();
                }

            }
        }
    }

    protected static boolean a(Context var0, String var1, List<CacheTrackInfo> var2) {
        a(var0);
        if(b == null) {
            return false;
        } else {
            StringBuffer var4;
            (var4 = new StringBuffer()).append("select entity_name").append(", count(*), min(loc_time").append("), max(loc_time").append(") from trace_location");
            String[] var3 = null;
            if(e.a(var1)) {
                var4.append(" where entity_name").append(" like ? ");
                var3 = new String[]{var1};
            } else {
                var4.append(" group by entity_name");
            }

            Cursor var5 = b.rawQuery(var4.toString(), var3);
            if(var5 == null) {
                return true;
            } else {
                while(var5.moveToNext()) {
                    if(e.a(var5.getString(0))) {
                        var2.add(new CacheTrackInfo(var5.getString(0), var5.getInt(1), var5.getLong(2), var5.getLong(3)));
                    } else if(e.a(var1)) {
                        var2.add(new CacheTrackInfo(var1, var5.getInt(1), var5.getLong(2), var5.getLong(3)));
                    }
                }

                if(var5 != null) {
                    var5.close();
                }

                return true;
            }
        }
    }

    protected static boolean a(Context var0, List<String> var1, List<CacheTrackInfo> var2) {
        a(var0);
        if(b == null) {
            return false;
        } else {
            b.beginTransaction();
            boolean var15 = false;

            label136: {
                try {
                    var15 = true;
                    var0 = null;
                    String[] var3 = null;
                    StringBuffer var18;
                    String var19;
                    int var23;
                    if(var2 != null && !var2.isEmpty()) {
                        Iterator var22 = var2.iterator();

                        while(var22.hasNext()) {
                            CacheTrackInfo var24 = (CacheTrackInfo)var22.next();
                            var18 = new StringBuffer();
                            String var20 = var24.getEntityName();
                            long var9 = var24.getStartTime();
                            long var11 = var24.getEndTime();
                            byte var25 = 0;
                            ArrayList var4 = new ArrayList();
                            if(e.a(var20)) {
                                var23 = var25 + 1;
                                var18.append("entity_name like ? ");
                                var4.add(var20);
                                if(var9 > 0L) {
                                    ++var23;
                                    var18.append(" and loc_time").append(" >= ? ");
                                    var4.add(String.valueOf(var9));
                                }

                                if(var11 > 0L) {
                                    ++var23;
                                    var18.append(" and loc_time").append(" <= ? ");
                                    var4.add(String.valueOf(var11));
                                }

                                var19 = var18.toString();
                                var3 = new String[var23];
                                var4.toArray(var3);
                                b.delete("trace_location", var19, var3);
                                var4.clear();
                            }
                        }
                    } else if(var1 != null && !var1.isEmpty()) {
                        var18 = new StringBuffer();
                        int var21 = var1.size();

                        for(var23 = 0; var23 < var21; ++var23) {
                            if(var23 < var21 - 1) {
                                var18.append("entity_name like ? or ");
                            } else {
                                var18.append("entity_name like ? ");
                            }
                        }

                        var19 = var18.toString();
                        var3 = new String[var1.size()];
                        var1.toArray(var3);
                        b.delete("trace_location", var19, var3);
                    } else {
                        b.delete("trace_location", (String)null, (String[])null);
                    }

                    b.setTransactionSuccessful();
                    var15 = false;
                    break label136;
                } catch (Exception var16) {
                    var15 = false;
                } finally {
                    if(var15) {
                        b.endTransaction();
                    }
                }

                boolean var26 = false;
                b.endTransaction();
                return false;
            }

            b.endTransaction();
            return true;
        }
    }

    protected static void a(Context var0) {
        if(var0 != null && (a == null || b == null)) {
            Class var1 = am.class;
            synchronized(am.class) {
                if(a == null) {
                    a = new u(var0);
                }

                if(b == null && !c) {
                    c = true;
                    (new an()).start();
                }

            }
        }
    }

    protected static void a(int var0) {
        if(var0 >= 50) {
            e = var0;
        }
    }

    private static void d() {
        if(b != null && e >= 50) {
            if(d == null) {
                d = new File(b.getPath());
            }

            long var0;
            if((var0 = e()) > 0L) {
                if(var0 / 1048576L > (long)e) {
                    if(b != null) {
                        b.beginTransaction();

                        try {
                            StringBuffer var6;
                            (var6 = new StringBuffer("delete from ")).append("trace_location where rowid in(select rowid from ").append("trace_location limit 0,?);");
                            String[] var1 = new String[]{String.valueOf(1000)};
                            u var10000 = a;
                            u.a(b, var6.toString(), var1);
                            b.setTransactionSuccessful();
                            return;
                        } catch (Exception var4) {
                            ;
                        } finally {
                            b.endTransaction();
                        }

                    }
                }
            }
        }
    }

    private static long e() {
        if(b == null) {
            return 0L;
        } else {
            try {
                if(d == null) {
                    d = new File(b.getPath());
                }

                long var0 = d.length();
                return var0;
            } catch (Exception var2) {
                return 0L;
            }
        }
    }

    protected static void a() {
        c = false;
        if(a != null || b != null) {
            try {
                if(a != null) {
                    a.close();
                    a = null;
                }

                if(b != null) {
                    b.close();
                    b = null;
                }
            } catch (Exception var0) {
                ;
            }

            d = null;
        }
    }

    public am(int var1, String var2) {
        this.f = var1;
        this.g = var2;
    }
}
